<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <%--  引入所有需要用到的css  --%>
    <jsp:include page="index/css.jsp" />
        <link rel="stylesheet" href="blog/css/pagination.css">
</head>
<body class="hold-transition sidebar-mini">
<style>
    .ui-jqgrid tr.jqgrow td {
        white-space: normal !important;
        height: auto;
        vertical-align: text-top;
        padding-top: 2px;
    }
</style>
<div class="wrapper">
    <!-- 引入页面头header.jsp -->
    <jsp:include page="index/header.jsp" />

    <!-- 引入工具栏left.jsp -->
    <jsp:include page="index/left.jsp" />

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <div class="content-header">
            <div class="container-fluid">
            </div><!-- /.container-fluid -->
        </div>
        <!-- Main content -->
        <div class="content">
            <div class="container-fluid">
                <div class="card card-primary card-outline">
                    <div class="card-header">
                        <h3 class="card-title">用户管理</h3>
                    </div> <!-- /.card-body -->
                    <div class="card-body">
                        <div class="grid-btn">
                            <button class="btn btn-info" onclick="editUser()"><i
                                    class="fa fa-edit"></i>&nbsp;修改
                            </button>
                            <button class="btn btn-danger" onclick="deleteUser()"><i
                                    class="fa fa-trash-o"></i>&nbsp;删除
                            </button>&nbsp;&nbsp;
                        </div>


                        <div class="widget-body">
                            <table class="table table-striped table-bordered" id="sample_1">
                                <thead>
                                <tr>
                                    <th style="width:8px;"><input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes" /></th>
                                    <th class="hidden-phone">用户名</th>
                                    <th class="hidden-phone">密保问题</th>
                                    <th class="hidden-phone">密保答案</th>
                                    <th class="hidden-phone">描述</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach items="${userList}" var="user">
                                    <tr class="odd gradeX">
                                        <td><input type="checkbox" class="checkboxes" value="1" /></td>
                                        <td class="center hidden-phone">${user.account}</td>
                                        <td class="hidden-phone">${user.problem}</td>
                                        <td class="hidden-phone">${user.answer}</td>
                                        <td class="hidden-phone">${user.identify}</td>
                                        <td name="hiddenPad" style="display: none" >${user.password}</td>
                                        <td name="hiddenId" style="display: none" >${user.id}</td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </div>
                        <form id="userForm" action="UserServlet" method="post">
                            <input type="hidden" name="op" value="">
                            <input type="hidden" name="userId" value="">
                        </form>


                    </div><!-- /.card-body -->
                </div>
            </div><!-- /.container-fluid -->
        </div>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <!-- 引入页脚footer-fragment -->
    <div replace="footer::footer-fragment"></div>
</div>
<!-- jQuery -->
<script src="admin/plugins/jquery/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="admin/plugins/jQueryUI/jquery-ui.min.js"></script>
<!-- Bootstrap 4 -->
<script src="admin/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="admin/dist/js/adminlte.min.js"></script>
<!-- jqgrid -->
<script src="admin/plugins/jqgrid-5.3.0/jquery.jqGrid.min.js"></script>
<script src="admin/plugins/jqgrid-5.3.0/grid.locale-cn.js"></script>
<!-- sweetalert -->
<script src="admin/plugins/sweetalert/sweetalert.min.js"></script>
<script src="admin/dist/js/public.js"></script>
<script>
    var idArray=[];
    function editUser(){
        if(idArray=="null"||idArray==null||idArray=="undefined"||idArray==undefined||idArray.length==0){
            swal("请选择一个进行修改", {
                icon: "error",
            });
            return;
        }

        if(idArray.length>1){
            swal("只能选择一个进行修改", {
                icon: "error",
            });
            return;
        }

        $("input:hidden[name='op']").val("updUser");
        // alert($("input:hidden[name='op']").val());
        $("input:hidden[name='userId']").val(idArray[0]);
        $("#userForm").submit();
    }
    function deleteUser(){
        if(idArray=="null"||idArray==null||idArray=="undefined"||idArray==undefined||idArray.length==0){
            swal("请选择要删除的数据", {
                icon: "error",
            });
            return;
        }
        swal({
            title: "确认弹框",
            text: "确认要删除id为["+idArray+"]这些数据吗?",
            icon: "warning",
            buttons: true,
            dangerMode: true,
        }).then((flag) => {
                if (flag) {
                    $("input:hidden[name='op']").val("delUser");
                    $("input:hidden[name='userId']").val(idArray);
                    $("#userForm").submit();
                }else{
                    $("input:hidden[name='op']").val("");
                }
            }
        );
    }
    $('.checkboxes').click(function () {
        if ($(this).prop("checked")) {
            idArray.push(parseInt($(this).parent().parent().find("td:eq(6)").html()))
        } else {
            var i=parseInt($(this).parent().parent().find("td:eq(6)").html());
            idArray.splice($.inArray(i,idArray),1);
        }
    })
    $(function () {
        if("${sessionScope.MSG}"==200){
            swal("保存成功", {
                icon: "success",
            });
        }else if("${sessionScope.MSG}"==201){
            swal("操作失败", {
                icon: "error",
            });
        }
    })
</script>
<%
    request.getSession().setAttribute("MSG","");
%>
</body>
</html>
